﻿using System;
using System.Collections.Generic;
using UnityEngine;
using System.Text;

public class ArchievementSystem : IGameSystem
{
    private int mEnemyKilledCount = 0;
    private int mSoldieryKilledCount = 0;
    private int mMaxStageLv = 1;


    public void AddEnemyKilledCount(int number = 1)
    {
        mEnemyKilledCount += number;
        Debug.Log("敌人击杀数量EnemyKilledCount:" + mEnemyKilledCount);
    }

    public void AddSoldierKilledCount(int number = 1)
    {
        mSoldieryKilledCount += number;
        // Debug.Log("战士死亡数SoldierKilledCount" + mSoldieryKilledCount);
    }

    public void SetMaxStageLv(int stageLv)
    {
        // 成就记录以高级为准
        if (stageLv > mMaxStageLv)
        {
            mMaxStageLv = stageLv;
        }

        //10
        Debug.Log("MaxStageLv" + mMaxStageLv);
    }

    public override void Init()
    {
        base.Init();
        GameFacade.Instance.RegisterObserver(GameEventType.EnemyKilled, new EnemyKillObserverArchievement(this));
        GameFacade.Instance.RegisterObserver(GameEventType.SoldierKilled, new SoldierKilledObserverArchievement(this));
        GameFacade.Instance.RegisterObserver(GameEventType.NewStage, new NewStageObserverArchievement(this));
    }

    // 保存
    public AchievementMemento CreateMemento()
    {
        AchievementMemento memento = new AchievementMemento();
        memento.enemyKilledCount = mEnemyKilledCount;
        memento.soldieryKilledCount = mSoldieryKilledCount;
        memento.maxStageLv = mMaxStageLv;
        return memento;
    }

    // 恢复
    public void SetMemento(AchievementMemento memento)
    {
        mEnemyKilledCount = memento.enemyKilledCount;
        mSoldieryKilledCount = memento.soldieryKilledCount;
        mMaxStageLv = memento.maxStageLv;
    }
}